
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>这是一个 阴影动画按钮 </title>
		<style>
			*{
				margin: 0;
				padding: 0;
			}
			.box{
				width: 500px;
				height: 500px;
				background: #00BFFF;
				display: inline-block;
				transition: all .;
				margin: 20px 10px;
			}
		</style>
	</head>
	<body>
		<div style="padding: 100px;">
			<div class="box"></div>
		</div>
		
	</body>
	<script>
		let box = document.querySelectorAll('.box')	
		document.onmousemove = function(event){
			//获取鼠标坐标位置
				let movex = event.clientX
				let movey = event.clientY
			//获取中心点
				for(let i=0;i<box.length;i++){
					let x = box[i].offsetLeft+box[i].offsetWidth/2
					let y = box[i].offsetTop+box[i].offsetHeight/2
					console.log(y)
					//计算阴影的位置
					let numx = (x-movex)/20
					let numy = (y-movey)/20
					box[i].style.boxShadow = `${numx}px ${numy}px 2px 0px rgba(100, 100, 100, 1)`
				}
		}
	</script>
</html>
